﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace SHFST.UI
{
   public class Menu
   {
      private TextDisplay title;
      private List<TextDisplay> options;
      public int selectedOption;
      private Point position;
      private Color normalColor;
      private Color selectColor;
      private SpriteFont menuFont;

      public void Load (string titleText, SpriteFont newTitleFont, SpriteFont newMenuFont, Point newPos, Color nColor, Color sColor)
      {
         menuFont = newMenuFont;
         position = newPos;
         normalColor = nColor;
         selectColor = sColor;

         title = new TextDisplay ();
         title.Load (newTitleFont, new Point (position.X, position.Y - 80));
         title.text = titleText;
         title.color = normalColor;

         options = new List<TextDisplay> ();
         selectedOption = 0;
      }

      public void Draw (SpriteBatch batch)
      {
         title.Draw (batch);
         foreach (TextDisplay option in options)
         {
            option.Draw (batch);
         }
      }

      public void addOption (string name)
      {
         TextDisplay newOption = new TextDisplay ();
         newOption.Load (menuFont, new Point (position.X, position.Y + options.Count * 30));
         newOption.text = name;
         newOption.color = normalColor;
         options.Add (newOption);
      }

      public void select (int indexChange)
      {
         options[selectedOption].color = normalColor;
         selectedOption += indexChange;
         if (selectedOption > options.Count - 1)
         {
            selectedOption %= options.Count;
         }
         else if (selectedOption < 0)
         {
            selectedOption = options.Count - 1;
         }
         options[selectedOption].color = selectColor;
      }
   }
}
